package com.daqian.chance.example.admin.modules.system.controller;

import com.daqian.chance.common.base.BaseController;
import com.daqian.chance.core.rest.RestResult;
import com.daqian.chance.example.admin.modules.system.po.dto.SysUserDTO;
import com.daqian.chance.example.admin.modules.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 系统-用户 前端控制器
 * </p>
 *
 * @author daqian
 * @since 2019-08-08
 */
@RestController
@RequestMapping("/sysUser")
public class SysUserController extends BaseController {

    @Autowired
    private ISysUserService iSysUserService;


    /**
     * 分页查询 系统-用户
     *
     * @author daqian
     */
    @GetMapping("page")
    public RestResult page(SysUserDTO sysUserDTO) {
        return RestResult.ok(iSysUserService.page(sysUserDTO));
    }

    /**
     * 根据id查询 系统-用户
     *
     * @author daqian
     */
    @GetMapping("info/{sysUserId}")
    public RestResult info(@PathVariable("sysUserId") Long sysUserId) {
        return RestResult.ok(iSysUserService.getById(sysUserId));
    }

    /**
     * 保存 系统-用户
     *
     * @author daqian
     */
    @PostMapping("save")
    public RestResult save(@RequestBody SysUserDTO sysUserDTO) {
        iSysUserService.save(sysUserDTO.convertToEntity());
        return RestResult.ok();
    }

    /**
     * 更新 系统-用户
     *
     * @author daqian
     */
    @PostMapping("update/{sysUserId}")
    public RestResult remove(@PathVariable("sysUserId") Long sysUserId, @RequestBody SysUserDTO sysUserDTO) {
        iSysUserService.updateById(sysUserDTO.convertToEntity().setId(sysUserId));
        return RestResult.ok();
    }

    /**
     * 根据id删除 系统-用户
     *
     * @author daqian
     */
    @DeleteMapping("{sysUserId}")
    public RestResult delete(@PathVariable("sysUserId") Long sysUserId) {
        iSysUserService.removeById(sysUserId);
        return RestResult.ok();
    }

}
